package com.qxl.forest.util;

import java.io.Serializable;

/**
 * @Author: qiuxinlin
 * @Dercription:
 * @Date: 19:44 2017/11/23
 */
public class CommRes<T> implements Serializable {
    private static final long serialVersionUID = 3991293264646158705L;
    private String msg;
    private String code;
    private T data;

    private CommRes() {
    }

    private CommRes(T data) {
        this("200", "OK", data);
    }

    private CommRes(String code, String msg) {
        this(code, msg, null);
    }

    private CommRes(String code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public String getMsg() {
        return this.msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public String getCode() {
        return this.code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public T getData() {
        return this.data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public static <T> CommRes<T> errorRes(String code, String msg) {
        return new CommRes(code, msg);
    }

    public static <T> CommRes<T> errorRes(String code, String msg, T data) {
        return new CommRes(code, msg, data);
    }

    public static <T> CommRes<T> success(T data) {
        return new CommRes("200", "OK", data);
    }

    public static <T> CommRes<T> successRes() {
        return new CommRes("200", "OK");
    }

    public static CommRes badRequestError() {
        return new CommRes("400", "参数错误");
    }

    public static CommRes innerError(String msg) {
        return new CommRes("500", msg);
    }
}
